package ACM;

import java.util.Scanner;

/**
 *
 *
 * 差不多了
 * @author way
 * @create 2025-03-29 10:43
 */
public class MeiTuan_2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        while (T-- > 0) {
            int n = sc.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
            }

            // 计算最长连续相同元素的长度
            int maxSame = 1, current = 1;
            for (int i = 1; i < n; i++) {
                if (arr[i] == arr[i - 1]) {
                    current++;
                    maxSame = Math.max(maxSame, current);
                } else {
                    current = 1;
                }
            }

            // 输出最少操作次数
            System.out.println(maxSame >= 2 ? n - maxSame : n - 1);
        }
        sc.close();
    }
}


